package com.codez.gznx.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 
 * @author dechao.zheng
 * @createTime: 2019-09-23 05:56:46	
 *
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
//@ExcelClass(titleRowIndex=2)
public class User extends ExcelHelper{
	
	@ExcelField(value="ID")
	@ValidateField(name="ID",rule=ValidateFieldRule.NOT_EMPTY)
	private Integer id;
	
	@ExcelField("姓名")
	@ValidateField(name="用户名",msg="[{0}]不能为空或空字符串",rule=ValidateFieldRule.NOT_EMPTY)
	private String username;

	@ExcelField(value="备注")
	private String remarks;

	@ExcelField(value="C")
	private Date createTime;
	
//	@Override
//	public String toString() {
////		return "User [id=" + id + ", username=" + username + ", remarks=" + remarks + ", getErrorMsg()=" + getErrorMsg()
////				+ "]" + new SimpleDateFormat("yyyyMMdd").format(getCreateTime());
//	}
	
	
	public static void main(String[] args) throws Exception {
		ExcelUtils excelUtils = new ExcelUtils();
		List<User> users = (List<User>) excelUtils.toBeanList(new FileInputStream(new File("d:/user.xls")), 
				User.class);
		if(!new ValidateService().validList(users)) {
			excelUtils.errorLookupRow(new FileInputStream(new File("d:/user.xls")),
					new FileOutputStream(new File("d:/user_error.xls")), users);
		}else {
			excelUtils.toExcel(users, new FileOutputStream("d:/user_.xls"));
		}
		
	}

}
